﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

public partial class image_list : Base
{
    public int classid = 0;
    public int colorid = 0;
    public string key = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        classid = base.QueryInt32("class");
        colorid = base.QueryInt32("color");
        key = base.Query("key");
        base.PageSize = 10;
        BindImage();
        BindColor();
        BindClass();

    }

    public void BindImage()
    {
        BLL.Img bll = new BLL.Img();
        StringBuilder sql = new StringBuilder();
        sql.AppendFormat(" IsPass =1 and ");
        if (colorid > 0) sql.AppendFormat(" ColorID={0} and ", colorid);
        if (classid > 0)
        {
            Model.Classification cl = new BLL.Classification().GetModelBystrWhere(" id=" + classid);
            if (cl != null) sql.AppendFormat(" Tag like '%{0}%' and ", cl.ClassName);
        }
        if (!string.IsNullOrEmpty(key))
        {
            sql.AppendFormat(" (Title like '%{0}%' or  Tag like '%{0}%' or Content like '%{0}%') and ", key);
        }
        if (sql.Length > 0) sql.Remove(sql.Length - 4, 4);
        string sort = " AddTime desc";
        Model.PageData<Model.Img> data = bll.GetList(10, base.PageIndex, sql.ToString(), sort);
        Repeater1.DataSource = data.DataSoure;
        Repeater1.DataBind();
        pgServer.RecordCount = data.Count;
        //pgServer.EnableUrlRewriting = true;
        //string url = string.Format("list-{0}-{1}-{2}.html", base.TypeID, base.ColorID, base.Language);
        //pgServer.UrlRewritePattern = url + "?page={0}";
        pgServer.DataBind();
    }
    public void BindColor()
    {
        BLL.Color bll = new BLL.Color();
        List<Model.Color> colors = bll.GetList(" IsShow =1 order by addtime desc ");
        this.rptColor.DataSource = colors;
        this.rptColor.DataBind();
    }
    public void BindClass()
    {
        BLL.Classification bll = new BLL.Classification();
        List<Model.Classification> colors = bll.GetList(" IsShow =1 order by Ordinal asc ");
        this.rptClass.DataSource = colors;
        this.rptClass.DataBind();
    }
}